import java.util.Scanner;

public class 摘花生 {
    public static void main(String[] args) {
        int n, m, T;
        int[][] w;
        int[][] f = new int[111][111];
        Scanner scan = new Scanner(System.in);
        T = scan.nextInt();

        w = new int[111][111];
        while (T-- > 0) {
            n = scan.nextInt();
            m = scan.nextInt();
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    w[i][j] = scan.nextInt();
                }
            }

            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    f[i][j] = Math.max(f[i - 1][j], f[i][j - 1]) + w[i][j];
                }
            }

            System.out.println(f[n][m]);
        }
    }
}